package com.android.webttest.Adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.android.webttest.model.Category;
import com.android.webttest.View.FrameLayout.GoodListFragment;

import java.util.List;

public class GoodPagerAdapter extends FragmentStateAdapter {

    private List<Category> categoryList;

    public GoodPagerAdapter(@NonNull FragmentActivity fragmentActivity, List<Category> categoryList) {
        super(fragmentActivity);
        this.categoryList = categoryList;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // 创建每个 Tab 对应的 Fragment
        // 创建每个 Tab 对应的 Fragment，并传递 categoryId
        return GoodListFragment.newInstance(categoryList.get(position).getId());
    }

    @Override
    public int getItemCount() {
        return categoryList.size();
    }
}
